class Electrician < ActiveRecord::Base
  attr_accessible :address, :initial_balance, :mobile, :mobile1, :name, :others
  has_many :transactions, :as => [:giver,:receiver]

  def current_balance()
    debit = 0;
    credit = 0;
    Transaction.find_all_by_receiver_type_and_receiver_id("Electrician",id).each do |transaction|
      debit = debit + transaction.amount
    end
    Transaction.find_all_by_giver_type_and_giver_id("Electrician",id).each do |transaction| 
      credit = credit + transaction.amount
    end
    return credit - debit + initial_balance
  end

end
